const mongoose = require("mongoose");

module.exports.deleteShopsById = async ShopsId => {
    return await mongoose.model("shopsModel").deleteOne(ShopsId);
}

module.exports.addShops = async newShops => {
    return await mongoose.model("shopsModel").create(newShops);
}
module.exports.getShops = async _id => {
    console.log(_id)
    return await mongoose.model("shopsModel").find(_id)
    .populate("adminId")
}

//修改
module.exports.updateShopsById = async ({newShops}) => {
    const {_id,name,phone,address,desc } = newShops;
    const data = await mongoose.model("shopsModel").update( {_id }, { name,phone,address,desc });
    return data
}  

module.exports.shopsDeleteApply = async (newShopsStatus) => {
    const {_id,type,status } = newShopsStatus;
    const data = await mongoose.model("shopsModel").update( {_id }, { type,status });
    return data
}

//驳回修改状态为status:3； 同意修改状态为status:2
module.exports.updateApplyById = async (msg) => {
    const { _id, status } = msg
    return await mongoose.model("shopsModel").updateOne({ _id } ,{ status })
}

module.exports.deleteApplysById = async _id => {
    return await mongoose.model("shopsModel").deleteOne(_id);
}


//搜索查询门店申请(模糊查询)
// module.exports.searchApplys = async ({ name }) => {
//     return await mongoose.model("shopsModel").find({ name: { $regex: name, $options: '$i' } })
//     // const a = await mongoose.model("applyModel").find({ name: { $regex: name, $options: '$i' } })
//     // console.log(a)
// }